# -*- coding: utf-8 -*-
"""
Created on Thu Aug 10 13:56:39 2023

@author: skunk69
"""

import json

chinese_name = u'中学生网络成瘾诊断量表'
english_name = 'Internet Addiction Disorder Diagnostic Scale for Middle School Students'
abbreviation = 'IADDS-MSS'
category = u'应激及相关行为量表'

outline = u"""13-18岁年龄段的中学生是网络成瘾的重灾区，而中学生年龄段又具有独特的心理和语言特点。为此，昝玲玲等根据项目反应理论编制了《中学生网络成瘾诊断量表》。"""

instruction = u"""此表是为了您的健康状况而设计，请您认真做出您的一项选择。"""

with open('IADDS-MSS.txt','r',encoding='utf-8') as f:
    lines = f.readlines()
    f.close()

items = {}
for line in lines:
    key,value = line.strip().split('.')
    items[key] = value.strip()

reverse_items = []
scales = [u'上网渴求与耐受',u'戒断反应',u'不良反应']
scales_items = [
    [1,2,9,10,13],# 上网渴求与耐受
    [3,4,6],# 戒断反应
    [5,7,8,11,12],# 不良反应
    ]

# check scales_items
print(f'scale length={[len(l) for l in scales_items]}')

check = []
for l in scales_items:
    check = check+l
print(f'len(check)={len(check)}')

# complementary set
check_set = {i for i in sorted(check)}^{i for i in range(1,14)}
print(f'complementary set= {check_set}')

factors = []
factors_scales = []
rating = [u'不是',u'是']
score_rules = [0,1]

contents = {
    'instruction':instruction,
    'items':items,
    'reverse_items':reverse_items,
    'scales':scales,
    'scales_items':scales_items,
    'factors':factors,
    'factors_scales':factors_scales,
    'rating':rating,
    'score_rules':score_rules       
    }

implementation = u"""《中学生网络成瘾诊断量表》属于一个自评量表。"""

reliability = u"""正式样本为部分中学生。采用双参数二值计分模型，进行IRT分析，结果表明，各项指标均符合项目反应理论要求。"""
validity = u"""结构效度良好。在效标关联效度方面，根据DSM-IV物质依赖分类与诊断标准，并参考Goldberg标准作为效标，对上网学生进行临床诊断，同时进行量表自评。结果显示，《中学生网络成瘾诊断量表》对中学生网络成瘾具有良好的鉴别能力。"""
measurements = {'reliability':reliability,'validity':validity}

interpretation = u"""13个条目总分大于5分即表明上网成瘾，分数的高低反映了成瘾的严重程度。"""

applications = u"""各项指标检验表明《中学生网络成瘾诊断量表》是可用的评定工具，实际应用效果尚待后续研究检验。"""

this_scale = {
    'chinese_name':chinese_name,
    'english_name':english_name,
    'abbreviation':abbreviation,
    'category':category,
    'outline':outline,
    'contents':contents,
    'implementation':implementation,
    'measurements':measurements,
    'interpretation':interpretation,
    'applications':applications    
    }

with open(abbreviation+'.json','w+',encoding='utf-8') as f:
    json.dump(this_scale,f,indent=2,ensure_ascii=False)